//============================================================================
// Name        : bounce_path.cpp
// Author      : dfoelber
//============================================================================

// INCLUDES //
#include "physics/bounce_path.h"
#include <iostream>
//////////////

using namespace std;

/**
* Default constructor.
**/
BouncePath::BouncePath() : Path()
{
}

/**
* Lets the path know that time has passed and to move accordingly.
* 
* Overridden from Path.
* 
* @param ms The time passed since last called
**/
void BouncePath::TimePassed( int ms )
{
	double distance = (double)ms / 50.0;
	
	switch( keyDir )
	{
		case DIRECTION_NONE:
			distance *= 2;
			
			if( xVel != 0 )
			{
				xVel = xVel < 0 ? xVel + distance : xVel - distance;
			}
			if( yVel != 0 )
			{
				yVel = yVel < 0 ? yVel + distance : yVel - distance;
			}
			if( xVel < distance && xVel > -distance )
			{
				xVel = 0;
			}
			if( yVel < distance && yVel > -distance )
			{
				yVel = 0;
			}
			break;
		case DIRECTION_UP: yVel -= distance; break;
        case DIRECTION_DOWN: yVel += distance; break;
        case DIRECTION_LEFT: xVel -= distance; break;
        case DIRECTION_RIGHT: xVel += distance; break;
	}
	
	xDistance = (int)xVel;
	yDistance = (int)yVel;
}

/**
* Input that can be used by the path.
* 
* Overridden from Path.
* 
* @param event The event
* @return If the event was consumed
**/
bool BouncePath::Input( SDL_Event event )
{
	//If a key was pressed
    if( event.type == SDL_KEYDOWN )
    {
        //Adjust the velocity
        switch( event.key.keysym.sym )
        {
        	case SDLK_UP: keyDir = DIRECTION_UP; break;
            case SDLK_DOWN: keyDir = DIRECTION_DOWN; break;
            case SDLK_LEFT: keyDir = DIRECTION_LEFT; break;
            case SDLK_RIGHT: keyDir = DIRECTION_RIGHT; break;   
            default:
            	break;
        }
        
        return true;
    }
    //If a key was released
    else if( event.type == SDL_KEYUP )
    {
    	keyDir = DIRECTION_NONE;
    	
        //Adjust the velocity
        switch( event.key.keysym.sym )
        {    
        	/*case SDLK_UP: yVel = 0; break;
            case SDLK_DOWN: yVel = 0; break;
            case SDLK_LEFT: xVel = 0; break;
            case SDLK_RIGHT: xVel = 0; break;*/
        	default:
        		break;
        }        
        
        return true;
    }
    
    return false;
}

/**
* Check if this path collided with another path.
* 
* Overridden from Path.
* 
* @param other The other path.
**/
void BouncePath::CheckCollision( Path* other )
{
}
